var i = getApp(),
    s = i.requirejs("core"),
    w = i.requirejs("wxParse/wxParse"),
    foxui = i.requirejs("foxui");
Page({
    data: {
        beforeColor: "rbga(0,0,0,.5)",
        afterColor: "white",
        adveradmin: !0,
        current: 0,
        indicatorDots: !0,
        autoplay: !0,
        interval: 5e3,
        duration: 500,
        circular: !0,
        storeRecommand: [],
        total: 1,
        page: 1,
        loading: false,
        loaded: false,
        bannerImg: [],
        merchid: 0,
        merch: [],
        keywords: "",
        cate: 1,
        service: [],
        staff: [],
        latitude: "",
        longitude: "",
        data: "",
        tao: [],
    },
    onLoad: function (t) {
        console.clear();
        var merchid = 0;
        if (t.merchid) merchid = t.merchid, console.log(t);
        if (t.scene) {
            var p = decodeURIComponent(t.scene);
            var scene = s.str2Obj(p);
            merchid = scene.merchid;
        }
        t = t || {};
        var a = this;
        if (merchid) {
            a.setData({
                imgUrl: i.globalData.approot,
                merchid: merchid
            })
        } else {
            a.setData({
                imgUrl: i.globalData.approot,
            })
        }
        s.get("black", {}, function (t) {
            t.isblack && wx.showModal({
                title: "无法访问",
                content: "您在商城的黑名单中，无权访问！",
                success: function (t) {
                    t.confirm && a.close(), t.cancel && a.close();
                }
            });
        });
        var e = decodeURIComponent(t.scene);
        if (!t.id && e) {
            var n = s.str2Obj(e);
            t.id = n.id, n.mid && (t.mid = n.mid, i.setCache("usermid", n));
        }
        s.get("syt.merch.get_detail", {}, res => {
            this.setData({
                bannerImg: res.merch.piclist,
                data: res.merch
            })
            s.get("syt.merch.ren_list", {
                id: this.data.data.id
            }, res => {
                this.setData({
                    staff: res.list
                })
            })
        })
        s.get("syt.merch.fu_list", {}, res => {
            console.log(res);
            this.setData({
                service: res.list
            })
        })
        s.get("syt.merch.to_list", {}, res => {
            this.setData({tao: res.list})
        })
    },
    onShow: function () {
        var t = this,
            a = wx.getSystemInfoSync(),
            e = i.getCache("sysset");
        wx.getSetting({
            success: function (a) {
                var e = a.authSetting["scope.userInfo"];
                t.setData({
                    imgUrl: i.globalData.approot
                });
            }
        });
        i.getCache("isIpx") ? t.setData({
            isIpx: !0,
            iphonexnavbar: "fui-iphonex-navbar",
            paddingb: "padding-b"
        }) : t.setData({
            isIpx: !1,
            iphonexnavbar: "",
            paddingb: ""
        })
        // 模拟部分数据
        t.setData({
            show: !0
        })
        var content = '<p><span style="font-size: 14px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;素颜堂还你婴儿般的容颜！打造出水芙蓉的你。</span></p>'
        w.wxParse("introduce", "html", content, t, 0);
        wx.setNavigationBarTitle({
            title: "素颜堂美容集团"
        });
        t.getLocation()

        s.get("syt.merch.get_detail", {}, res => {
            this.setData({
                bannerImg: res.merch.piclist,
                data: res.merch
            })
            s.get("syt.merch.ren_list", {
                id: this.data.data.id
            }, res => {
                this.setData({
                    staff: res.list
                })
            })
        })
        
    },
    onReachBottom: function () {
        if (this.data.page != 1)
            this.data.loaded || this.data.storeRecommand.length == this.data.total || this.getRecommand();
    },
    getRecommand: function () {
        var t = this;
        t.setData({
            loading: true
        }), s.get("shop/get_merchgoods", {
            cate: t.data.cate,
            merchid: t.data.merchid,
            page: t.data.page,
            keywords: t.data.keywords,
        }, function (a) {
            var i = {
                loading: false,
                total: a.total,
                pagesize: a.pagesize,
                show: !0
            };
            a.list.length > 0 && (i.page = t.data.page + 1, i.storeRecommand = t.data.storeRecommand.concat(a.list),
                a.list.length < a.pagesize && (i.loaded = true)), t.setData(i);
        });
    },
    getLocation: function () {
        var that = this;
        wx.getLocation({
            type: "gcj02",
            success: function (res) {
                that.setData({
                    latitude: res.latitude,
                    longitude: res.longitude,
                })
                // ,that.getList()
            },
            fail: function (t) {
                wx.showModal({
                    title: "提示",
                    content: "请打开位置信息，定位商家距离！",
                    showCancel: false,
                    confirmText: "确定",
                    success: (data) => {
                        if (data.confirm) {
                            that.setData({
                                latitude: "",
                                longitude: "",
                            })
                            // , that.getList();
                        }
                    }
                })
            }
        })
    },
    cate: function (p) {
        var cate = p.currentTarget.dataset.type;
        this.setData({
            storeRecommand: [],
            page: 1,
            cate: cate,
            loaded: false,
        })
    },
    url: function (p) {
        var url = "",
            userinfoOpenid = i.getCache("userinfo_openid");
        if (userinfoOpenid) url = p.currentTarget.dataset.url;
        else url = "/pages/auth/index"
        wx.navigateTo({
            url: url,
        })
    },
    urlreLaunch: function (p) {
        var url = p.currentTarget.dataset.url;
        wx.reLaunch({
            url: url,
        })
    },
    call: function (p) {
        let phone = p.currentTarget.dataset.tel;
        wx.makePhoneCall({
            phoneNumber: phone,
            success: function () {
                console.log("成功！");
            },
            fail: function () {
                console.log("失败！");
                return
            }
        })
    },
    loca: function (p) {
        let dataset = p.currentTarget.dataset,
            lat = parseFloat(dataset.lat),
            lng = parseFloat(dataset.lng),
            nme = dataset.name,
            add = dataset.address;
        wx.openLocation({
            latitude: lat,
            longitude: lng,
            name: nme,
            address: add
        })
    },
    bindInput: function (t) {
        this.setData({
            inputValue: t.detail.value
        });
    },
});